#include "StdAfx.h"


namespace DLNLib
{
	Data::Data(void)
		:value(0)
	{
	}

	Data::~Data(void)
	{
	}

	const Data& Data::operator=( const Data& rhs )
	{
		time = rhs.time;
		value= rhs.value;
		return *this;
	}
	
	Data* Parse( char* line )
	{
		//if not a dln data , return NULL
		if(!SKTLib::IsDLNFmt(line) || strlen(line)==0)
			return NULL;
		// parse dln data 
		CString Source(line);
		//10:00:00	03.05.2008	3.520			
		CStringArray Deliminator;
		Deliminator.Add(":");
		Deliminator.Add("	");
		Deliminator.Add(".");
		Deliminator.Add("\n");

		CStringArray AddIt;

		SKTLib::Split(Source,Deliminator,AddIt,false);
		size_t size = AddIt.GetSize();
		//ASSERT(size == 8);
		Data* newItem = new Data();
		newItem->time.SetDateTime(atoi(AddIt.GetAt(5)),
			atoi(AddIt.GetAt(4)),
			atoi(AddIt.GetAt(3)),
			atoi(AddIt.GetAt(0)),
			atoi(AddIt.GetAt(1)),
			atoi(AddIt.GetAt(2)));
		newItem->value = (float)(atof(AddIt.GetAt(6)) + (atof(AddIt.GetAt(7))/1000.0));
		return newItem;
	}

	bool Parse2( Data& rD,char* line )
	{
		//if not a dln data , return NULL
		if(!SKTLib::IsDLNFmt(line) || strlen(line)==0)
			return false;
		// parse dln data 
		CString Source(line);
		//10:00:00	03.05.2008	3.520			
		CStringArray Deliminator;
		Deliminator.Add(":");
		Deliminator.Add("	");
		Deliminator.Add(".");
		Deliminator.Add("\n");

		CStringArray AddIt;

		SKTLib::Split(Source,Deliminator,AddIt,false);
		size_t size = AddIt.GetSize();
		//ASSERT(size == 8);
		
		rD.time.SetDateTime(atoi(AddIt.GetAt(5)),
			atoi(AddIt.GetAt(4)),
			atoi(AddIt.GetAt(3)),
			atoi(AddIt.GetAt(0)),
			atoi(AddIt.GetAt(1)),
			atoi(AddIt.GetAt(2)));
		rD.value = (float)(atof(AddIt.GetAt(6)) + (atof(AddIt.GetAt(7))/1000.0));
		return true;
	}
	
}